import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    add(state) {
      // setTimeout(() => {
      //   state.count ++
      // }, 1000)
      state.count ++
    },
    addN(state, step) {
      state.count += step
    },
    sub(state) {
      state.count --
    },
    subN(state, step) {
      state.count -= step
    }
  },
  actions: {
    addAsync(context){
      setTimeout(() => {
        context.commit('add')
      }, 1000)
    },
    addNAsync(context, step) {
      setTimeout(() => {
        context.commit('addN', step)
      }, 3000)
    },
    subAsync(context) {
      setTimeout(() => {
        context.commit('sub')
      }, 1000)
    },
    subNAsync(context, step) {
      setTimeout(() => {
        context.commit('subN', step)
      }, 1000) 
    }
  },
  modules: {
  }
})
